<?php

namespace App\Console\Commands;

use App\Models\Factory;
use App\Service\BaiduMapToGeo;
use Illuminate\Console\Command;

class FactoryLatToTengxunCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'lat:to';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '百度坐标转化腾讯';
    protected $baiduMapToGeo;
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(BaiduMapToGeo  $baiduMapToGeo)
    {
        $this->baiduMapToGeo=$baiduMapToGeo;
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Factory::chunkById(100,function ($factories){
            foreach ($factories as $factory){
                /**
                 * @var Factory $factory
                 */
             [$lat,$lng]=   $this->baiduMapToGeo->geoconv(5,$factory->baidu_lat,$factory->baidu_lng,3);
            $factory->tengxun_lat=$lat;
            $factory->tengxun_lng=$lng;
            $factory->save();
            }
        });
        return 0;
    }
}
